import axios from 'axios'

// 添加收货地址
export function addAddress(data) {
  return axios.post('/api/addresses', data)
}

// 获取地址详情
export function getAddress(id) {
  return axios.get(`/api/addresses/${id}`)
}

// 更新地址
export function updateAddress(data) {
  return axios.put(`/api/addresses/${data.id}`, data)
}

// 删除地址
export function deleteAddress(id, userId) {
  return axios.delete(`/api/addresses/${id}?userId=${userId}`)
}

// 获取用户地址列表
export function getAddressList(userId) {
  return axios.get(`/api/addresses/user/${userId}`)
}

// 获取用户地址列表 (兼容旧API)
export function getUserAddresses(userId) {
  return axios.get(`/api/addresses/user/${userId}`)
}

// 获取用户默认地址
export function getUserDefaultAddress(userId) {
  return axios.get(`/api/addresses/default/${userId}`)
}

// 设置默认地址
export function setDefaultAddress(id, userId) {
  return axios.put(`/api/addresses/${id}/default?userId=${userId}`)
}

// 获取用户地址数量
export function getUserAddressCount(userId) {
  return axios.get(`/api/addresses/count/${userId}`)
}

// 搜索用户地址
export function searchUserAddresses(userId, keyword) {
  return axios.get(`/api/addresses/search/${userId}?keyword=${keyword}`)
}

// 批量删除地址
export function batchDeleteAddresses(ids, userId) {
  return axios.delete(`/api/addresses/batch?ids=${ids.join(',')}&userId=${userId}`)
} 